#!/bin/bash
# description:　Rsync war file
# version:	1.0
# author:	zhangyanbin
# contact:	yanbin_zhang@foxitsoftware.com
#
. /etc/init.d/functions.sh

# "master" or "develop"
usage()
 {
	echo "usage: `basename $0` \$1"
	echo "\$1 :specfify a branch (develop/master)"
}

if [ -z $1 ]; then
#echo "ERROR: please specfify a branch (develop/master)"
	usage
	exit -1
fi

BRANCH=$1

if [ "$DL_SERVER" = "" ]; then
error_and_log "Download server url is empty. Please check $DL_SERVER_FILE_NAME"
exit -1;
else
warning_and_log "Download Server Url is: $DL_SERVER"
fi

GENERIC_SRC=smx@${DL_SERVER}:/opt/www/ops30.sumilux.com

echo "--> Begin to download CMIS war file,branch = $BRANCH "
if [ ! -e /opt/cmis-server ]; then
mkdir -p /opt/cmis-server
fi

CMIS_FILE_SRC=smx@${DL_SERVER}:/opt/www/${DL_SERVER}/cmis-server/latest/${BRANCH}/
CMIS_FILE_DST=/opt/cmis-server/
rsync ${RSYNC_OPTS} -e "${RSH_OPTS}" ${CMIS_FILE_SRC} ${CMIS_FILE_DST} 1>/dev/null

 if [ ! -e /var/lib/tomcat/webapps ]; then
mkdir -p /var/lib/tomcat/webapps
 fi

cp /opt/cmis-server/chemistry-opencmis-server-jcr-1.0.0-SNAPSHOT.war /var/lib/tomcat/webapps/cmis.war